﻿using CinemaMaestro.BusinessLayer.Contracts;
using CinemaMaestro.Common.IocContainer;
using CinemaMaestro.DataLayer.Contracts.Entities;
using CinemaMaestro.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace CinemaMaestro.WebApi.Controllers
{
    public class LanguageController : ApiController
    {
        [HttpGet]
        public IEnumerable<LanguageViewModel> GetAllLanguages()
        {
            var businessUoW = Resolver.Get<IBusinessObjectFactory>();
            return businessUoW.Languages.Read().Select<Language, LanguageViewModel>(x => x).ToList();
        }

        [HttpGet]
        public IHttpActionResult GetLanguage(int id)
        {
            var businessUoW = Resolver.Get<IBusinessObjectFactory>();
            var language = businessUoW.Languages.Read().FirstOrDefault(x => x.Id == id);
            if (language == null)
            {
                return NotFound();
            }
            LanguageViewModel languageVM = language;
            return Ok(languageVM);
        }

    }
}
